home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library / Microsoft Programmer's Library (CD-ROM Database)(125-099-008)(Version 1.1a)(CDRM 162100)(1989).iso / SAMPCODE / ADVOS2 / CH07 / SHOWCOM.C
Text File  |  1988-12-12  |  7KB  |  163 lines

  1. /*
  2.     SHOWCOM.C --- Simple program to display current COM1 
  3.                   setup using the DosDevIOCtl calls.
  4.     Copyright (C) 1987 Ray Duncan
  5.  
  6.     Build:  C>CL showcom.c
  7.     Usage:  C>SHOWCOM
  8. */
  9.  
  10. #include <stdio.h>
  11.  
  12. #define COMPORT "COM1"              /* COM device name */
  13.  
  14. #define API unsigned extern far pascal
  15.  
  16. API DosClose(unsigned); 
  17. API DosDevIOCtl(void far *, void far *, unsigned, unsigned, unsigned);
  18. API DosOpen(char far *, unsigned far *, unsigned far *, unsigned long,
  19.             unsigned, unsigned, unsigned, unsigned long);           
  20.  
  21. struct F61Struc {
  22.     int BaudRate;                   /* 110, 150, 300, ... 19200 */
  23.     } F61Info ;
  24.  
  25. struct F62Struc {
  26.     unsigned char DataBits;         /* possible values 5-8 */
  27.     unsigned char Parity;           /* 0=N 1=O 2=E 3=Mark 4=Space */
  28.     unsigned char StopBits;         /* 0=1 bit, 1=1.5 bits, 2=2 bits */
  29.     unsigned char Break;            /* 0=not xmitting break */
  30.     } F62Info;
  31.  
  32. struct F64Struc {
  33.     unsigned char ComPortStatus;    /* bit  meaning         */
  34.     } F64Info;                      /*  0   Tx waiting for CTS ON
  35.                                         1   Tx waiting for DSR ON
  36.                                         2   Tx waiting for DCD ON
  37.                                         3   Tx waiting, XOFF rcvd
  38.                                         4   Tx waiting, XOFF sent
  39.                                         5   Tx waiting, break xmit
  40.                                         6   Char waiting to xmit
  41.                                         7   Rcv waiting for DSR on  */
  42.  
  43. struct F65Struc {
  44.     unsigned char XmitDataStatus;   /* bit  meaning         */
  45.     } F65Info;                      /*  0   write in prog or queued
  46.                                         1   data in xmit queue
  47.                                         2   char xmit in progress
  48.                                         3   char waiting for xmit
  49.                                         4   waiting to send XON
  50.                                         5   waiting to send XOFF
  51.                                         6-7 undefined       */
  52.  
  53. struct F66Struc {
  54.     unsigned char OutputSignals;    /* bit  meaning         */
  55.     } F66Info;                      /*  0   DTR (data terminal ready)
  56.                                         1   RTS (request to send)
  57.                                         2-7 undefined       */
  58.  
  59. struct F67Struc {
  60.     unsigned char InputSignals;     /* bit  meaning         */
  61.     } F67Info;                      /* 0-3  undefined
  62.                                         4   CTS (clear to send)
  63.                                         5   DSR (data set ready)    */
  64.  
  65. struct F68Struc {
  66.     unsigned CharsQueued;           /* chars received and waiting */
  67.     unsigned QueueSize;             /* size of receive char. queue */
  68.     } F68Info;
  69.  
  70. struct F69Struc {
  71.     unsigned CharsQueued;           /* chars waiting for xmit */
  72.     unsigned QueueSize;             /* size of transmit char. queue */
  73.     } F69Info;
  74.  
  75. struct F6dStruc {
  76.     unsigned ComError;              /* bit  meaning         */
  77.     } F6dInfo;                      /*  0   receive queue overrun
  78.                                         1   receive hardware overrun
  79.                                         2   parity error detected
  80.                                         3   framing error detected
  81.                                         4-15 undefined      */
  82.  
  83. struct F72Struc {
  84.     unsigned EventWord;             /* bit  meaning         */
  85.     } F72Info;                      /*  0   set when char read
  86.                                             placed in receive queue
  87.                                         1   undefined
  88.                                         2   set when last char in
  89.                                             transmit queue is sent
  90.                                         3   change in CTS state
  91.                                         4   change in DSR state
  92.                                         5   change in DCD state
  93.                                         6   break detected
  94.                                         7   parity or framing error
  95.                                         8   trailing edge of ring
  96.                                             indicator detected
  97.                                         9-15 undefined      */
  98.  
  99. static char *ParityNames[] = { "None", "Odd", "Even", "Mark", "Space" };
  100. static char *StopNames[]   = { "1", "1.5", "2" };
  101.  
  102. main (int argc,char *argv[])
  103. {
  104.     int action, handle, status;     /* scratch variables */
  105.     int openflag = 0x01;                        /* DosOpen fail if device not found */
  106.     int openmode = 0x42;            /* DosOpen read/write, deny none */
  107.  
  108.                                     /* open device or exit */
  109.     if(DosOpen(COMPORT, &handle, &action, 0L, 0, openflag, openmode, 0L))
  110.     {   
  111.         fprintf(stderr, "\nCan't open %s device\n", COMPORT);
  112.         exit(1);
  113.     }                               /* got device OK */
  114.     printf("\n%s device opened, handle = %d\n", COMPORT, handle);
  115.  
  116.                                     /* now display device info */
  117.     status = DosDevIOCtl(&F61Info, NULL, 0x61, 1, handle);
  118.     if(! status) printf("\nBaud rate:          %d", F61Info.BaudRate);
  119.  
  120.     status = DosDevIOCtl(&F62Info, NULL, 0x62, 1, handle);
  121.     if(! status)
  122.     {   
  123.         printf("\nData Bits:          %d", F62Info.DataBits);
  124.         printf("\nParity:             %s", ParityNames[F62Info.Parity]);
  125.         printf("\nStop Bits:          %s", StopNames[F62Info.StopBits]);
  126.     }
  127.  
  128.     status = DosDevIOCtl(&F64Info, NULL, 0x64, 1, handle);
  129.     if(! status) printf("\nCom Port Status:    %.2xh", F64Info.ComPortStatus);
  130.  
  131.     status = DosDevIOCtl(&F65Info, NULL, 0x65, 1, handle);
  132.     if(! status) printf("\nTransmit Status:    %.2xh", F65Info.XmitDataStatus);
  133.  
  134.     status = DosDevIOCtl(&F66Info, NULL, 0x66, 1, handle);
  135.     if(! status) printf("\nOutput Signals:     %.2xh", F66Info.OutputSignals);
  136.  
  137.     status = DosDevIOCtl(&F67Info, NULL, 0x67, 1, handle);
  138.     if(! status) printf("\nInput Signals:      %.2xh", F67Info.InputSignals);
  139.  
  140.     status = DosDevIOCtl(&F68Info, NULL, 0x68, 1, handle);
  141.     if(! status) 
  142.     {   
  143.         printf("\nRcv Chars Queued:   %d", F68Info.CharsQueued);
  144.         printf("\nRcv Queue Size:     %d", F68Info.QueueSize);
  145.     }
  146.  
  147.     status = DosDevIOCtl(&F69Info, NULL, 0x69, 1, handle);
  148.     if(! status) 
  149.     {   
  150.         printf("\nXmit Chars Queued:  %d", F69Info.CharsQueued);
  151.         printf("\nXmit Queue Size:    %d", F69Info.QueueSize);
  152.     }
  153.  
  154.     status = DosDevIOCtl(&F6dInfo, NULL, 0x6d, 1, handle);
  155.     if(! status) printf("\nCom Error Info:     %.4xh", F6dInfo.ComError);
  156.  
  157.     status = DosDevIOCtl(&F72Info, NULL, 0x72, 1, handle);
  158.     if(! status) printf("\nEvent Word:         %.4xh", F72Info.EventWord);
  159.  
  160.     status = DosClose(handle);      /* an unnecessary nicety */
  161.     if(! status) printf("\n\n%s device closed\n", COMPORT);
  162. }
  163.